package entity.thread;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListTest {

    public static void main(String[] args) throws InterruptedException {
//        List<String> safeList =new ArrayList<String>();

        List<String> safeList= Collections.synchronizedList(new ArrayList<String>());
//        List<String> safeList = new CopyOnWriteArrayList<String>();


        for (int i = 1; i <= 20000; i++) {
            new Thread(() -> {
                safeList.add(Thread.currentThread().getName());
            }).start();
        }
        System.out.println(safeList.size());
    }
}
